package com.ruoyi.crm.modules.mq;

import com.ruoyi.crm.domain.Contract;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.ruoyi.crm.modules.mq.CrmRabbitConfig.*;

/**
 * 消息生产者
 */
@Component
public class CrmMqProducer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 生产合同创建的消息
     * @param contract
     */
    public void produceContractCreatedMessage(Contract contract){
//        convertAndSend（交换机，路由key，发送的对象）
        rabbitTemplate.convertAndSend(CRM_EXCHANGE_CONTRACT,CRM_ROUTING_KEY_CONTRACT_CREATED,contract);
    }
}
